<template>
  <a-modal :title="title" :visible="visible" @ok="handleSave" @cancel="handleClose" width="950px">
    <a-form ref="form" :form="form">
      <a-row :gutter="48">
        <template v-if="!isBatch">
          <a-col :sm="{span:6}" :lg="{span:6}" :xl="{span:6}">
            <a-form-item label="学号">
              <a-input disabled v-model="data.xh" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:6}" :lg="{span:6}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input disabled v-model="data.xm" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:6}" :lg="{span:6}" :xl="{span:6}">
            <a-form-item label="院系">
              <a-input disabled v-model="data.ssyxmc" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:6}" :lg="{span:6}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-input disabled v-model="data.sszymc" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
            <a-form-item label="学科门类">
              <a-input disabled v-model="data.xkmc" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
            <a-form-item label="学生类别">
              <a-input disabled v-model="data.xslbmc" />
            </a-form-item>
          </a-col>
          <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
            <a-form-item label="导师姓名">
              <a-input disabled v-model="data.dsxm" />
            </a-form-item>
          </a-col>
        </template>
        
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="委员总数">
            <a-input-number :min="0" v-decorator="[
                'wyzs',
                {
                  rules: [{ required: true, message: '请输入委员总数!' }]
                }
              ]" style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="同意票数">
            <a-input-number :min="0" v-decorator="[
                'typs',
                {
                  rules: [{ required: true, message: '请输入同意票数!' }]
                }
              ]" style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="到会人数">
            <!-- <a-input-number :min="0" v-decorator="[
                'dhrs',
                {
                  rules: [{ required: true, message: '请输入到会人数!' }]
                }
              ]" style="width: 100%" /> -->
              <a-input disabled v-model="dhrs" />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="反对票数">
            <a-input-number :min="0" v-decorator="[
                'fdps',
                {
                  rules: [{ required: true, message: '请输入反对票数!' }]
                }
              ]" style="width: 100%" />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="审核结果">
            <a-select v-decorator="[
                'shjg',
                {
                  rules: [{ required: true, message: '请选择审核结果!' }]
                }
              ]" :allowClear="true" showSearch optionFilterProp="children" >
              <a-select-option v-for="i in TYPE0374" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="{span:8}" :lg="{span:12}" :xl="{span:8}">
          <a-form-item label="弃权票数">
            <a-input-number :min="0" v-decorator="[
                'qqps',
                {
                  rules: [{ required: true, message: '请输入弃权票数!' }]
                }
              ]" style="width: 100%" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-alert message="说明：1、委员总数=同意票数时，为全票通过，学部会、校委会默认审核通过。（审核结果必须为通过）2、到会人数＝同意票数+反对票数+弃权票数" type="error" />
    </a-form>
  </a-modal>
</template>
<script>
import { mapState } from 'vuex'
export default {
  props: {
    visible: {
      default: false
    },
    data: {
      default: function() {
        return {}
      }
    },
    title:{
      default: ""
    },
    isBatch:{
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form : this.$form.createForm(this,{
        onValuesChange:this.handleConclusion
      }),
      dhrs:0,
    }
  },
  watch:{
    data(val){
      this.$nextTick(() => {
        if (val.id) {
          this.form.setFieldsValue({
            wyzs:val.wyzs,
            typs:val.typs,
            fdps:val.fdps,
            shjg:val.shjg,
            qqps:val.qqps
          })
        } else {
          this.form.resetFields()
        }
      })
    }
  },
  computed: {
    ...mapState({
      TYPE0374: state => state.app['TYPE0374'] // 审核结果
    })
  },
  mounted() {
    let val = this.data;
    if (val.id) {
      setTimeout(()=>{
          this.form.setFieldsValue({
            wyzs:val.wyzs,
            typs:val.typs,
            fdps:val.fdps,
            shjg:val.shjg,
            qqps:val.qqps
          })
      },100)
    }
  },
  methods: {
    handleConclusion(props,vals){
      if (vals) {
          let values = this.form.getFieldsValue(['typs','fdps','qqps'])
          Object.assign(values,vals)
          console.log(values)
          for (let n in values) {
           let elem = values[n];
            elem>-1?values[n] = Number(elem):values[n] = 0
          }
          console.log('你妈')
          let dhrs = values.typs+values.fdps+values.qqps;
          console.log('你妈')
         this.dhrs = dhrs;
      }
    },
    handleSave() {
      this.form.validateFields(
        (err,values) => {
          if (!err) {
            values.dhrs = this.dhrs;
            this.$emit('success',values)
          }
        },
      );
    },
    handleClose() {
      this.$emit('close')
    }
  }
}

</script>
